package cn.dwj.hadoop.mr.wordcount;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * Created by Administrator on 2017/12/25 0025.
 */
public class WCReduce extends Reducer<Text, LongWritable, Text, LongWritable>{

    //框架在map处理完成之后，将所有kv对缓存起来进行分组，然后传递一个组<key, values>，调用一次reduce方法
    @Override
    protected void reduce(Text key, Iterable<LongWritable> values, Context context) throws IOException, InterruptedException {
        long count = 0;
        for(LongWritable value: values){
            count = count + value.get();
        }
        //输出这一个单词的统计结果
        context.write(key, new LongWritable(count));
    }
}
